home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / libnixV1_0.lha / gnu / libnix-sources.lha / sources / headers / stdio.h < prev    next >
C/C++ Source or Header  |  1995-04-29  |  4KB  |  112 lines

  1. #ifndef STDIO_H
  2. #define STDIO_H
  3. #include <stdarg.h>
  4. #include <exec/lists.h>
  5. #include <exec/nodes.h>
  6.  
  7. /* Adjusted to be compatible with the bsd headers
  8.  * (At least for normal ANSI stuff)
  9.  * Member names are not the same, but they need not be :-)
  10.  */
  11.  
  12. typedef long fpos_t;
  13.  
  14. typedef struct __FILE
  15. {
  16.   unsigned char *p;      /* pointer to actual character */
  17.   int incount;          /* Bytes left in buffer for reading, writemode: 0 */
  18.   int outcount;       /* Space left in buffer for writing + fp->linebufsize,
  19.                * readmode: 0 
  20.                            */
  21.   short flags;          /* Some flags: 0x01 line buffered
  22.                *         0x02 unbuffered
  23.                *         0x04 read mode
  24.                *         0x08 write mode
  25.                *         0x20 EOF read
  26.                *         0x40 error encountered
  27.                            *             0x80 buffer malloc'ed by library
  28.                *         0x200 sprintf/sscanf buffer 
  29.                            */
  30.   short file;             /* The filehandle */
  31.   unsigned char *buffer;  /* original buffer pointer */
  32.   int bufsize;          /* size of the buffer */
  33.   int linebufsize;      /* 0 full buffered
  34.                * -bufsize line buffered&write mode
  35.                * readmode: undefined */
  36. /* from this point on not binary compatible to bsd headers */
  37.   unsigned char unget[4]; /* ungetc buffer 4 bytes necessary (for -Na*)
  38.                            * ANSI requires 3 bytes (for -.*), so one more
  39.                            * doesn't matter
  40.                            */
  41.   unsigned char *tmpp;      /* Stored p if ungetc pending, otherwise NULL */
  42.   int tmpinc;          /* Stored incount if ungetc pending, otherwise undefined */
  43.   long tmpdir;            /* lock to directory if temporary file */
  44.   char *name;             /* filename if temporary file */
  45. } FILE;
  46.  
  47. #ifndef NULL
  48. #define NULL ((void *)0l)
  49. #endif
  50. #define BUFSIZ 1024
  51. #define EOF (-1)
  52. #define SEEK_SET 0
  53. #define SEEK_CUR 1
  54. #define SEEK_END 2
  55. #define _IOFBF 0
  56. #define _IOLBF 1
  57. #define _IONBF 2
  58.  
  59. extern FILE *fopen(const char *filename,const char *mode);
  60. extern FILE *freopen(const char *filename,const char *mode,FILE *stream);
  61. extern int fclose(FILE *stream);
  62. extern int fgetc(FILE *stream);
  63. extern int fputc(int c,FILE *stream);
  64. extern int ungetc(int c,FILE *stream);
  65. extern int sprintf(char *s,const char *format,...);
  66. extern int sscanf(const char *s,const char *format,...);
  67. extern int vprintf(const char *format,va_list args);
  68. extern int vsprintf(char *s,const char *format,va_list args);
  69. extern int vfprintf(FILE *stream,const char *format,va_list args);
  70. extern int vscanf(const char *format,va_list args);
  71. extern int vsscanf(const char *s,const char *format,va_list args);
  72. extern int vfscanf(FILE *stream,const char *format,va_list args);
  73. extern int fseek(FILE *stream,long int offset,int whence);
  74. extern int fputs(const char *s,FILE *stream);
  75. extern long int ftell(FILE *stream);
  76. extern int setvbuf(FILE *stream,char *buf,int mode,unsigned long size);
  77.  
  78. /* More bsd headers compatibility */
  79.  
  80. extern int __swbuf(int c,FILE *stream);
  81. extern int __srget(FILE *stream);
  82. extern FILE **__sF; /* Standard I/O streams */
  83. #define stdin  (__sF[0]) /* Other streams are not in __sF */
  84. #define stdout (__sF[1])
  85. #define stderr (__sF[2])
  86.  
  87. /* Be careful: We have side effects and use incount in __srget -
  88.                must use comma-operator */
  89. #define getc(fp) ((fp)->incount--,(fp)->incount>=0?(int)*(fp)->p++:__srget(fp))
  90. #define putc(c,fp) \
  91. ((fp)->outcount--,(fp)->outcount>=0|| \
  92. ((fp)->outcount>=(fp)->linebufsize&&(char)(c)!='\n')? \
  93. *(fp)->p++=(c):__swbuf((c),(fp)))
  94. #define ferror(fp) ((fp)->flags&64)
  95. #define feof(fp)   ((fp)->flags&32)
  96.  
  97. /* own stuff */
  98. extern struct MinList __filelist;   /* List of all fopen'ed files */
  99. extern unsigned long *__stdfiledes; /* List of Amiga OS filehandles */
  100. extern struct MinList __memorylist; /* List of memory puddles */
  101.  
  102. extern int __fflush(FILE *stream); /* fflush single file */
  103. extern void __chkabort(void);      /* check for SIGABRT */
  104.  
  105. struct filenode /* objects in __filelist */
  106. {
  107.   struct MinNode node;
  108.   FILE FILE;
  109. };
  110.  
  111. #endif
  112.